package View.StoreManage.sDeleteMan;

import View.StoreManage.MyTool.ShowMan;
import View.StoreManage.sMenu.sMenu;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
import sx.dao.SalesManDao;
import sx.entity.SalesMan;

import java.net.URL;
import java.util.ResourceBundle;

/*删除售货员信息，输入sid，点击删除按钮，删除整条记录*/
public class sDeleteMan extends Application implements Initializable {

    @FXML
    private Label s3;        //显示删除成功与否

    @FXML
    private TableView<SalesMan> s4;     //显示所有售货员

    @FXML
    private TableColumn<String, String> spasswordColumn;

    @FXML
    private TableColumn<String, String> snameColumn;

    @FXML
    private TableColumn<String, String> sidColumn;

    @FXML
    private Button back;        //返回二级页面按钮

    @FXML
    private TextField s1;     //输入售货员ID

    @FXML
    private Button s2;        //删除按钮


    String sname;

    @Override
    public void start(Stage primaryStage) {
        try {
            Class clazz = getClass();
            Parent parent = FXMLLoader.load(clazz.getResource("sDeleteMan.fxml"));
            Scene scene = new Scene(parent, 600, 600);
            scene.getStylesheets().add(getClass().getResource("/sources/Css/application1.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    @FXML
    //点击删除按钮
    public void sDelete(){
        sname=this.s1.getText();    //输入姓名
        new SalesManDao().deleteSalesMan(sname);  //调用Dao包
        try {
            new sDeleteMan().start(new Stage());   //返回到删除界面
            exitButtonOnMouseClicked(back);
        } catch (Exception e) {
            // TODO: handle exception
        }
    }


    public void showList(){



        sidColumn.setCellValueFactory(new PropertyValueFactory("sId"));   //映射售货员编号
        snameColumn.setCellValueFactory(new PropertyValueFactory("sName"));
        spasswordColumn.setCellValueFactory(new PropertyValueFactory("sPassWord")); //映射


    }

    @FXML
    //返回到二级页面，商店管理
    public void sBack(){
        try {
            new sMenu().start(new Stage());   //返回到商品管理界面
            exitButtonOnMouseClicked(back);
        } catch (Exception e) {
            // TODO: handle exception
        }


    }

    //关闭本界面
    private void exitButtonOnMouseClicked(Button exitButton) {
        Stage stage = (Stage) exitButton.getScene().getWindow();
        stage.close();
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        new ShowMan().showList(s4,sidColumn,snameColumn,spasswordColumn);



    }
}
